<template>
  <div class="setOilPrice">
    <el-form :model="form" :rules="rules" ref="ruleForm" label-width="80px">
      <el-form-item label="油气价格" prop="oil_money">
        <el-input v-model="form.oil_money" placeholder="输入油气价格"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('ruleForm')">确定</el-button>
        <!-- <el-button>取消</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>
  
  <script>
import { setOil } from "@/api/businessUser/moneyManagment";
export default {
  name: "setOilPrice",
  props: {
    formInfo: {
      default: {},
      type: Object
    }
  },
  data() {
    return {
      form: {
        yund_id: "",
        oil_money: ""
      },
      rules: {
        oil_money: [
          { required: true, message: "请输入大于0的整数", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              const num = Number(value);
              if (!Number.isInteger(num)) {
                callback(new Error("请输入整数"));
              } else if (num <= 0) {
                callback(new Error("请输入大于0的整数"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ]
      }
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
        this.form.oil_money = this.formInfo.oil_money;
        this.form.yund_id = this.formInfo.yund_id;
    },
    onSubmit(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          let result = await setOil(this.form);
          if (result.code == 200) {
            this.$message.success(result.msg || "设置油价成功");
            setTimeout(() => {
              this.$emit("closeDialog",this.form.oil_money);
            }, 500);
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>
  
  <style lang="scss" scoped>
.setOilPrice {
}
</style>
  